package b2.scene.fight.skills
{
	import b2.config.EnemySkillAreaConfig;
	import b2.config.EnemySkillConfig;
	import b2.scene.fight.BulletSprite;
	import b2.scene.fight.PlayState;
	import b2.scene.fight.TankSprite;
	
	import org.flixel.FlxG;
	
	public class Frost implements ISkill
	{
		private var direction:int;
		private var tankId:int;
		private var bullet:BulletSprite;
		private var level:int;
		private var areaConfig:EnemySkillAreaConfig;
		
		public function Frost(bullet:BulletSprite = null, skillConfig:EnemySkillConfig = null)
		{
			if (bullet)
			{
				this.bullet = bullet;
				this.tankId = bullet.tankId;
				areaConfig = skillConfig.areas[0];
			}
		}

		public function checkSkillTriggerPremise():Boolean
		{
			return true;
		}
		
		public function discharge():void
		{
			var playerState:PlayState = FlxG.state as PlayState;
			var skillArea:SkillArea = new SkillArea(bullet.x + bullet.width / 2, bullet.y + bullet.height / 2, bullet.direction);
			if (areaConfig)
				skillArea.addCrossArea(areaConfig.front, areaConfig.back, areaConfig.left, areaConfig.right);
			for (var tankIdStr:String in playerState.tanks)
			{
				var otherTank:TankSprite = playerState.tanks[tankIdStr];
				if (otherTank != null && (tankId > 0 && otherTank.tankId < 0 || tankId < 0 && otherTank.tankId > 0))
				{
					if (skillArea.contain(otherTank.x + PlayState.TILE_WIDTH / 2, otherTank.y + PlayState.TILE_WIDTH / 2))
					{
						onHit(otherTank);
					}
				}
			}
		}
		private function onHit(tankOnHit:TankSprite):void
		{
			(FlxG.state as PlayState).updateTankStatus(tankOnHit.tankId, tankId, tankOnHit.currentHp, -areaConfig.demageValue, 0, 0, true, true);
		}
	}
}